<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "shipping_template".
 *
 * @property integer $id
 * @property string $name
 * @property integer $shipping_id
 * @property string $config
 * @property string $create_time
 */
class ShippingTemplate extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shipping_template';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'shipping_id', 'config'], 'required'],
            [['shipping_id'], 'integer'],
            [['config'], 'string'],
            [['create_time'], 'safe'],
            [['name'], 'string', 'max' => 64],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '模板Id',
            'name' => '模板名称',
            'shipping_id' => '快递id',
            'config' => '配送配制',
            'create_time' => '创建时间',
        ];
    }
public function beforeSave($insert) {
        if (parent::beforeSave($insert)) {
            //是否是新添加
            if($this->isNewRecord) {
               // if(!$this->status) $this->status = 1;
                
                $this->create_time = date("Y-m-d H:i:s", time());
               // $this->update_time = date("Y-m-d H:i:s", time());
            }else{
               // $this->update_time = date("Y-m-d H:i:s", time());
            }
            return true;
        } else {
            return false;
        }
    } 
   
}
